package process;

import com.xuly.ActivitiSpringBootApplication;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ActivitiSpringBootApplication.class)
@Slf4j
public class QueryHelper {
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private TaskService taskService;
    @Autowired
    private RuntimeService runtimeService;
    @Test
    public void queryRuTask(){
        String userId="zhangsan";
        List<Task> taskList=taskService.createTaskQuery()
//                .processInstanceBusinessKey("leave_service")
//                .taskAssignee(userId)
//                .taskCandidateOrAssigned(userId)
                .list();
        if (taskList != null && taskList.size() > 0) {
            for (Task task : taskList) {
                log.info("任务ID:" + task.getId());
                log.info("任务名称:" + task.getName());
                log.info("任务的创建时间:" + task.getCreateTime());
                log.info("任务的办理人:" + task.getAssignee());
                log.info("流程实例ID：" + task.getProcessInstanceId());
                log.info("执行对象ID:" + task.getExecutionId());
                log.info("流程定义ID:" + task.getProcessDefinitionId());
                log.info("业务键businessKey:" + runtimeService.createProcessInstanceQuery()
                        .processInstanceId(task.getProcessInstanceId())
                        .singleResult().getBusinessKey());
                log.info("********************************************");
            }
        }else {
            log.info("没有找到任务!");
        }
    }

}
